package com.fastcms.cms.service.impl;

import java.time.LocalDateTime;

import javax.validation.constraints.NotNull;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fastcms.cms.entity.Firm;
import com.fastcms.cms.mapper.FirmMapper;
import com.fastcms.cms.service.IFirmService;
import com.fastcms.common.exception.FastcmsException;
import com.fastcms.common.exception.I18nFastcmsException;

/**
 * 律所入驻服务实现类
 * @author wjun_java@163.com
 * @since 2021-05-23
 */
@Service
public class FirmServiceImpl extends ServiceImpl<FirmMapper, Firm> implements IFirmService {

	@Override
	public Page<Firm> pageFirm(Page pageParam, QueryWrapper queryWrapper) {
		return getBaseMapper().pageFirm(pageParam, queryWrapper);
	}


	@Override
	public void saveFirm(@NotNull String ename,@NotNull String name, @NotNull String mobile,@NotNull String content) throws FastcmsException {

		if(StringUtils.isBlank(ename)) {
			throw new I18nFastcmsException("律所名称不能为空");
		}
		
		if(StringUtils.isBlank(name)) {
			throw new I18nFastcmsException("联系人不能为空");
		}

		if(StringUtils.isBlank(mobile)) {
			throw new I18nFastcmsException("手机号码不能为空");
		}
		

		Firm firm = new Firm();
		firm.setEname(ename);
		firm.setName(name);
		firm.setMobile(mobile);
		firm.setContent(content);
		firm.setCreateTime(LocalDateTime.now());
		firm.setUpdateTime(LocalDateTime.now());		

		save(firm);
	}

}
